package com.nav.backend.mapper;

import com.nav.backend.pojo.TreeLine;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * MapMapper 接口用于定义和地图相关的数据库操作
 *
 * @author xiukira
 */
@Mapper
public interface MapMapper {

    /**
     * 搜索林荫道
     *
     * @param treeLineName String 林荫道名
     * @return 林荫道列表 List<TreeLine>
     */
    @Select("SELECT * FROM tree_line WHERE tree_line_name LIKE #{treeLineName}")
    List<TreeLine> searchBoulevard(String treeLineName);

    /**
     * 添加林荫道搜索历史记录
     *
     * @param treeLineName String 林荫道名
     * @param account String 账户名
     */
    @Insert("INSERT INTO tree_line_search (tree_line_name,account) values (#{treeLineName},#{account})")
    void addTreeLineSearch(String treeLineName, String account);

    /**
     * 获取所有林荫道
     *
     * @return 所有林荫道列表
     */
    @Results({
            @Result(property = "tree_line_id", column = "tree_line_list_id"),
            @Result(property = "tree_line_name", column = "tree_line_list_name"),
            @Result(property = "tree_line_distance", column = "tree_line_list_distance"),
            @Result(property = "tree", column = "tree_line_list_tree")
    })
    @Select("SELECT * FROM tree_line_list")
    List<TreeLine> searchBoulevardListAll();

    /**
     * 添加林荫道搜索历史记录前查重
     *
     * @param treeLineName String 林荫道名
     * @param account String 账户名
     * @return 林荫道搜索历史
     */
    @Select("select * from tree_line_search where tree_line_name = #{treeLineName} and account = #{account}")
    TreeLine checkTreeLineSearch(String treeLineName, String account);
}
